﻿using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Camc.Quality.Authorization.Users;
using Camc.Quality.Business;
using Camc.Quality.Chat;
using Abp.Linq.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.UI;
using Camc.Quality.Bop.IbopInterface;
using Camc.Quality.Bom;
using Camc.Quality.Bop;
using Camc.Quality.Quality;
using Camc.Quality.Authorization.Roles;
using Camc.Quality.Authorization.Users.Dto;
using System.Reflection;
using System.ComponentModel;
using Abp.Authorization.Users;
using Camc.Quality.Common;

namespace Camc.Quality.WorkFlow
{

    public class WorkFlowAppService : QualityAppServiceBase, ISendMessageService
    {
        private readonly IChatMessageManager _chatMessageManager;
        private readonly IRepository<WorkFlowNode, Guid> _workFlowNodeRepository;
        private readonly IRepository<WokFlow, int> _workFlowRepository;
        private readonly IRepository<BusinessApplication, Guid> _businessApplicationRepository;
        private readonly IRepository<BusinessApplicationLog, Guid> _businessApplicationLogRepository;
        private readonly IRepository<User, long> _userRepository;
        private readonly IRepository<AffairMessage, Guid> _affairMessageRepository;
        private readonly IRepository<WorkAuditor, Guid> _workAuditorRepository; 
        private readonly IRepository<BomDesign, Guid> _bomDesignrepository;
        private readonly IRepository<BomDesignDetail, Guid> _bomDesignDetailrepository;
        private readonly IRepository<BopNode, Guid> _bopNodeRepository;
        private readonly IRepository<TechniqueEntity, Guid> _techniqueEntityRepository;
        private readonly IRepository<Role> _roleRepository;
        private readonly IRepository<UserRole, long> _userRoleRepository;
        public WorkFlowAppService(IRepository<WorkFlowNode, Guid> workFlowNodeRepository,
            IRepository<WokFlow, int> workFlowRepository,
            IRepository<BusinessApplication, Guid> businessApplicationRepository,
            IChatMessageManager chatMessageManager,
            IRepository<BusinessApplicationLog, Guid> businessApplicationLogRepository,
            IRepository<User, long> userRepository,
            IRepository<AffairMessage, Guid> affairMessageRepository,
            IRepository<WorkAuditor, Guid> workAuditorRepository,
            IRepository<BomDesign, Guid> bomDesignrepository,
            IRepository<BopNode, Guid> bopNodeRepository,
            IRepository<TechniqueEntity, Guid> techniqueEntityRepository,
            IRepository<BomDesignDetail,Guid> bomDesignDetailrepository,
            IRepository<Role> roleRepository,
            IRepository<UserRole, long> userRoleRepository
            )
        {
            _workFlowNodeRepository = workFlowNodeRepository;
            _workFlowRepository = workFlowRepository;
            _businessApplicationRepository = businessApplicationRepository;
            _chatMessageManager = chatMessageManager;
            _businessApplicationLogRepository = businessApplicationLogRepository;
            _userRepository = userRepository;
            _affairMessageRepository = affairMessageRepository;
            _bomDesignrepository = bomDesignrepository;
            _workAuditorRepository = workAuditorRepository;
            _bopNodeRepository = bopNodeRepository;
            _techniqueEntityRepository = techniqueEntityRepository;
            _bomDesignDetailrepository = bomDesignDetailrepository;
            _roleRepository = roleRepository;
            _userRoleRepository = userRoleRepository;
        }
        /// <summary>
        /// 新增或者修改节点类型
        /// </summary>
        /// <param name="workFlowDto"></param>
        public void CreateOrUpdateWorkFlow(WorkFlowDto workFlowDto)
        {
            var workFlow = ObjectMapper.Map<WokFlow>(workFlowDto);
            _workFlowRepository.InsertOrUpdate(workFlow);
        }
        /// <summary>
        /// 新增节点
        /// </summary>
        /// <param name="workFlowNodeDto"></param>
        public ResultMessage CreateWorkFlowNode(WorkFlowNodeDto workFlowNodeDto)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                if (workFlowNodeDto.WnID != null)
                {
                    var workNodeList = _workFlowNodeRepository.GetAll().Where(d => d.WnID == workFlowNodeDto.WnID);
                    if (workNodeList.Count() > 0)
                    {
                        _workFlowNodeRepository.Delete(d => d.WnID == workFlowNodeDto.WnID);
                    }
                    foreach (var item in workFlowNodeDto.workNodes)
                    {
                        _workFlowNodeRepository.Insert(ObjectMapper.Map<WorkFlowNode>(item));
                    }
                    resultMessage.code = 0;
                    return resultMessage;
                }
                resultMessage.code = 1;
                resultMessage.Message = "新增节点失败";
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 获取所有审批类型
        /// </summary>
        /// <returns></returns>
        public PagedResultDto<WorkFlowDto> GetWorkFlowName(WorkTypePage workTypePage)
        {
            var temp = ObjectMapper.Map<List<WorkFlowDto>>(_workFlowRepository.GetAll().PageBy(workTypePage));
            var conut = _workFlowRepository.GetAll().Count();
            return new PagedResultDto<WorkFlowDto>(conut, temp);
        }
        /// <summary>
        /// 获取审批流程下拉框
        /// </summary>
        /// <returns></returns>
        public List<WorkLabelOutPut> GetWorkDropList()
        {
            var query = from temp in _workFlowRepository.GetAll()
                        select new WorkLabelOutPut
                        {
                            Label = temp.WfName,
                            Value = temp.Id
                        };
            return query.ToList();
        }

        ///<summary>
        ///  获取某一审批类型的审批流
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public List<WorkNode> GetWorkNodeById(WorkNodeInputDto inputDto)
        {
            var query = _workFlowNodeRepository.GetAll().Where(d => d.WnID == inputDto.winId).Where(d=>d.NodeType==2).OrderBy(d=>d.WfID);
            var result=  ObjectMapper.Map<List<WorkNode>>(query);
            var roleMap = from temp in _roleRepository.GetAll() select new { id = temp.Id, roleDesc = temp.DisplayName };
            foreach (var item in result)
            {
                if (!string.IsNullOrEmpty(item.Handlers))
                {
                    item.RoleDesc = roleMap.Where(d => d.id == Convert.ToInt32(item.Handlers)).FirstOrDefault().roleDesc;
                }
               
            }
            return result;
        }
        /// <summary>
        /// 发起流程
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Guid PushBusinessApplication(PushBusInput input)
        {
            BusinessApplication businessApplication =new BusinessApplication();
            businessApplication.BusinessDesc = input.BusinessDesc;
            businessApplication.UserID = GetCurrentUser().Id;
            businessApplication.UserName = GetCurrentUser().Surname + GetCurrentUser().Name;
            businessApplication.BAppType = input.Type;// 1工艺规程变更
            businessApplication.Status = 2;
            businessApplication.ApprovalDesc = ApprovalState.审批中;
            businessApplication.Id = Guid.NewGuid();
            businessApplication.FunModule = input.FunModule;
            businessApplication.Menu = input.Menu;
            businessApplication.ApplicationDate = DateTime.Now;
            businessApplication.BusinessNumber = input.BusinessNumber;
            if (input.WorkAuditorList.Count > 0)
            {
                var firstNode = input.WorkAuditorList.FirstOrDefault(d => d.WfID == 2);
                //firstNode.Result = 0;
                //firstNode.IsModif = true;
                businessApplication.ExamineUserId = firstNode.UserId;
                var workFlowNode = _workFlowNodeRepository.GetAll().Where(d => d.WnID == firstNode.WnID);
                var curNode = workFlowNode.Where(w => w.WnID == firstNode.WnID).FirstOrDefault();
                var auditors = ObjectMapper.Map<List<WorkAuditor>>(input.WorkAuditorList);
                var title = _workFlowRepository.Get(businessApplication.BAppType).WfName;
                var currentUser = _userRepository.Get(businessApplication.UserID);
                SendWorkFlowMessage(currentUser.Id, Convert.ToInt32(businessApplication.ExamineUserId), curNode.Handlers, title,
                    currentUser.Surname + currentUser.Name + "于" + DateTime.Now + "发起的" + title + "审批需要您审批！", businessApplication.Id, MessageSendingMode.UserToUser);
                foreach (var item in auditors)
                {
                    item.BappId = businessApplication.Id;
                    _workAuditorRepository.Insert(item);
                }
            }
            else
            {
                throw new UserFriendlyException("该审批流程未配置相应的审批人员!请重新提交!");
            }
            _businessApplicationRepository.Insert(businessApplication);
            return businessApplication.Id;
        }

        public Guid RejectPushBusinessApplication(RejectPushBusInput input)
        {
            BusinessApplication businessApplication = _businessApplicationRepository.Get(input.Id);
            businessApplication.UserID = GetCurrentUser().Id;
            businessApplication.UserName = GetCurrentUser().Surname + GetCurrentUser().Name;
            businessApplication.BAppType = input.Type;// 1工艺规程变更
            businessApplication.Status = 2;
            businessApplication.ApprovalDesc = ApprovalState.审批中;
            //businessApplication.Id = Guid.NewGuid();
            //businessApplication.FunModule = input.FunModule;
            //businessApplication.Menu = input.Menu;
            businessApplication.ApplicationDate = DateTime.Now;
            //businessApplication.BusinessNumber = Guid.NewGuid().ToString();
            if (input.WorkAuditorList.Count > 0)
            {
                var oldWorkAuditorList = _workAuditorRepository.GetAll().Where(d => d.BappId == input.Id).ToList();
                for (int i = 0; i < oldWorkAuditorList.Count; i++)
                {
                    _workAuditorRepository.Delete(oldWorkAuditorList[i]);
                }
                var firstNode = input.WorkAuditorList.FirstOrDefault(d => d.WfID == 2);
                //firstNode.Result = 0;
                //firstNode.IsModif = true;
                businessApplication.ExamineUserId = firstNode.UserId;
                var workFlowNode = _workFlowNodeRepository.GetAll().Where(d => d.WnID == firstNode.WnID);
                var curNode = workFlowNode.Where(w => w.WnID == firstNode.WnID).FirstOrDefault();
                var auditors = ObjectMapper.Map<List<WorkAuditor>>(input.WorkAuditorList);
                var title = _workFlowRepository.Get(businessApplication.BAppType).WfName;
                var currentUser = _userRepository.Get(businessApplication.UserID);
                SendWorkFlowMessage(currentUser.Id, Convert.ToInt32(businessApplication.ExamineUserId), curNode.Handlers, title,
                    currentUser.Surname + currentUser.Name + "于" + DateTime.Now + "发起的" + title + "审批需要您审批！", businessApplication.Id, MessageSendingMode.UserToUser);
                foreach (var item in auditors)
                {
                    item.BappId = businessApplication.Id;
                    _workAuditorRepository.Insert(item);
                }
            }
            else
            {
                throw new UserFriendlyException("该审批流程未配置相应的审批人员!请重新提交!");
            }
            _businessApplicationRepository.Update(businessApplication);
            return businessApplication.Id;
        }


        /// <summary>
        /// 重新提交
        /// </summary>
        /// <param name="bappId"></param>
        public void ReSubmit(Guid bappId)
        {
            var business = _businessApplicationRepository.FirstOrDefault(d => d.Id == bappId);
            if (business != null)
            {
                business.ExamineUserId = null;
                business.Opinion = "";
                business.ApprovalDesc = 0;
                business.Status = 0;
                _businessApplicationRepository.Update(business);
                var auditor = _workAuditorRepository.GetAll().Where(d => d.BappId == bappId);
                foreach (var item in auditor)
                {
                    item.Remark = "";
                    item.Result = 0;
                    item.AuditTime = null;
                    _workAuditorRepository.Update(item);
                }
                int Status = 0;
                SendToFlow(bappId, 1,"",out Status);
            }
        }
        public void SendToFlow(Guid bappId, int Operation,string Remark,  out int Status)
        {
            var businessApplication = _businessApplicationRepository.Get(bappId);
            Status = businessApplication.Status;
            var workFlowNode = _workFlowNodeRepository.GetAll().Where(d => d.WnID == businessApplication.BAppType);
            if (workFlowNode != null)
            {
                var curNode = workFlowNode.Where(w => w.WfID == businessApplication.Status).FirstOrDefault();
                if (curNode != null)
                {
                    var operation = Newtonsoft.Json.JsonConvert.DeserializeObject<List<OperationFlow>>(curNode.Condition);
                    var nextWfId = operation.Where(c => c.f == Operation).FirstOrDefault().n;
                    var nextNode = workFlowNode.FirstOrDefault(d => d.WfID == nextWfId);
                    if (nextNode != null)
                    {  
                        //2  就更新状态 和审批结构   99 完成  100 驳回 
                        if (nextNode.NodeType == 2)
                        {
                            businessApplication.ExamineUserId = _workAuditorRepository.GetAll().FirstOrDefault(d => d.BappId == businessApplication.Id && d.WnID == nextNode.WnID && d.WfID == nextNode.WfID).UserId;
                            var auditor = _workAuditorRepository.GetAll().FirstOrDefault(d => d.BappId == businessApplication.Id && d.WnID == curNode.WnID && d.WfID == curNode.WfID);
                            auditor.Result = 1;
                            auditor.Remark = Remark;
                            auditor.AuditTime = DateTime.Now;
                            _workAuditorRepository.Update(auditor);
                        }
                        businessApplication.Status = nextNode.WfID;
                        Status = nextNode.WfID;
                        if (nextNode.WfID == 99)
                        {
                            var auditor = _workAuditorRepository.GetAll().FirstOrDefault(d => d.BappId == businessApplication.Id && d.WnID == curNode.WnID && d.WfID == curNode.WfID);
                            auditor.Result = 1;
                            auditor.Remark = Remark;
                            auditor.AuditTime = DateTime.Now;
                            _workAuditorRepository.Update(auditor);
                            businessApplication.ApprovalDesc = ApprovalState.已通过;
                        }
                        if (nextNode.WfID == 100)
                        {
                            var auditor = _workAuditorRepository.GetAll().FirstOrDefault(d => d.BappId == businessApplication.Id && d.WnID == curNode.WnID && d.WfID == curNode.WfID);
                            auditor.Result = 2;
                            auditor.Remark = Remark;
                            auditor.AuditTime = DateTime.Now;
                            _workAuditorRepository.Update(auditor);
                            businessApplication.ApprovalDesc = ApprovalState.已驳回;
                            businessApplication.Opinion = Remark;
                        }
                        _businessApplicationRepository.Update(businessApplication);
                        var currentUser = GetCurrentUser();
                        if (nextNode.NodeType == 2)
                        {
                            var title = _workFlowRepository.Get(businessApplication.BAppType).WfName;
                            SendWorkFlowMessage(currentUser.Id, Convert.ToInt32(businessApplication.ExamineUserId), nextNode.Handlers, title,
                               currentUser.Surname + currentUser.Name + "于" + DateTime.Now + "发起的" + title + "审批需要您审批！", businessApplication.Id, MessageSendingMode.UserToUser);
                        }
                        else
                        {
                            //var roleList = currentUser.Roles.Select(d => d.RoleId);
                            //string res = string.Join(",", roleList);
                            var title = _workFlowRepository.Get(businessApplication.BAppType).WfName;
                            SendWorkFlowMessage(currentUser.Id, businessApplication.UserID, null, title,
                                "您于" + DateTime.Now + "发起的" + title + "审批已结束!审批结果为" + nextNode.WnName, businessApplication.Id, MessageSendingMode.UserToUser);
                        }
                        //记录操作日志
                        BusinessApplicationLog businessApplicationLog = new BusinessApplicationLog();
                        businessApplicationLog.OperationtId = GetCurrentUser().Id;
                        businessApplicationLog.BAppType = businessApplication.BAppType;
                        businessApplicationLog.OperationtContent = Operation.ToString();
                        businessApplicationLog.BAppId = businessApplication.Id;
                        _businessApplicationLogRepository.Insert(businessApplicationLog);
                    }
                }
                else
                {
                    throw new UserFriendlyException("系统未找到相应的审批节点!请联系管理员配置！");
                }
            }
        }

        /// <summary>
        /// 获取我发起的审批
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagedResultDto<BusinessApplicationDto> GetMyApplication(MyApprovalInput input)
        {
            var application = _businessApplicationRepository.GetAll().Where(d => d.UserID == GetCurrentUser().Id).OrderByDescending(o => o.CreationTime);
            int count = 0;
            var tempData = (from temp in application
                           join temp1 in _workFlowRepository.GetAll() on temp.BAppType equals temp1.Id
                           join temp2 in _workFlowNodeRepository.GetAll() on temp.Status equals temp2.WfID
                           orderby temp.ApplicationDate descending
                            where temp2.WnID== temp1.Id
                           select new BusinessApplicationDto
                           {
                               Id = temp.Id,
                               BAppId= temp.Id,
                               BAppType = temp.BAppType,
                               FunModule = temp.FunModule,
                               Menu = temp.Menu,
                               BusinessNumber= temp.BusinessNumber,
                               BusinessDesc= temp.BusinessDesc,
                               ApplicationDate = temp.ApplicationDate,
                               BAppTypeDesc = temp1.WfName,
                               ApprovalDesc = GetEnumDesc(temp.ApprovalDesc),
                               ApprovalNode = temp2.WnName
                           });
            count = tempData.Count();
            tempData = tempData.WhereIf(!string.IsNullOrEmpty(input.BusinessNumber), d => d.BusinessNumber.Contains(input.BusinessNumber))
                .WhereIf(input.BAppType != null, d => d.BAppType == input.BAppType);
            if (tempData.Count() > 0)
            {
                tempData = tempData.PageBy(input);
            }
            return new PagedResultDto<BusinessApplicationDto>(count, tempData.ToList());
        }
        /// <summary>
        /// 获取已审批的节点
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public PagedResultDto<ApplicationLogDto> GetApprovaled(GetApprovalInputDto inputDto)
        {
            var users = _userRepository.GetAll().ToList();
            var currentUser = GetCurrentUser();
            var query =
                    from temp1 in _businessApplicationLogRepository.GetAll().OrderBy(d=>d.LastModificationTime)
                    join temp2 in _businessApplicationRepository.GetAll() on temp1.BAppId equals temp2.Id
                    join temp3 in users on temp2.UserID equals temp3.Id
                    join temp4 in _workFlowRepository.GetAll() on temp2.BAppType equals temp4.Id
                    orderby temp2.ApplicationDate descending
                    where temp1.OperationtId == currentUser.Id
                    select new ApplicationLogDto
                    {
                        BusinessNumber= temp2.BusinessNumber,
                        BusinessDesc= temp2.BusinessDesc,
                        BAppId = temp1.BAppId,
                        OperationtId = temp1.OperationtId,
                        OperationtContent = temp1.OperationtContent == "1" ? "同意" : "否定",
                        BAppType = temp2.BAppType,
                        FunModule = temp2.FunModule,
                        Menu = temp2.Menu,
                        UserName = temp3.Surname + temp3.Name,
                        UserID = temp3.Id,
                        WfName = temp4.WfName,
                        ApplicationDate = temp2.ApplicationDate
                    };
            int count = 0;
            if (inputDto.userNameList!=null)
            {
                query = query.Where(d => inputDto.userNameList.Contains(d.UserName));
            }
            if (inputDto.bappTypeList != null)
            {
                query = query.Where(d => inputDto.bappTypeList.Contains(d.BAppType.Value));
            }
            count = query.Count();
            query = query.PageBy(inputDto);
            return new PagedResultDto<ApplicationLogDto>(count, query.ToList());
        }
        /// <summary>
        /// 获取所有发起人姓名
        /// </summary>
        /// <returns></returns>
        public List<string> GetApprovalPersonName()
        {
            var query =
                  from temp1 in _businessApplicationRepository.GetAll()
                  join temp2 in _userRepository.GetAll() on temp1.UserID equals temp2.Id
                  select new
                  {
                      UserName = temp2.Surname + temp2.Name,
                  };
            return query.Select(d => d.UserName).ToList();
        }
        /// <summary>
        /// 获取待审批的业务
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public PagedResultDto<ApplicationLogDto> GetApprovaling(GetApprovalInputDto inputDto)
        {
            var users = _userRepository.GetAll().ToList();
            var currentUser = GetCurrentUser();
      //      var currentRoles = _userRoleRepository.GetAll()
      //.Where(userRole => userRole.UserId == currentUser.Id)
      //.Select(userRole => userRole.RoleId).ToArray();
            List<ApplicationLogDto> applicationLogs = new List<ApplicationLogDto>();
            IQueryable<ApplicationLogDto> query;
            query =
            from temp1 in _businessApplicationRepository.GetAll()
            join temp2 in _workFlowRepository.GetAll() on temp1.BAppType equals temp2.Id 
            join temp3 in users on temp1.UserID equals temp3.Id
            orderby temp1.ApplicationDate descending
            where (temp1.Status != 99 && temp1.Status != 100) & (temp1.ExamineUserId == currentUser.Id) /*|| currentUser.Roles.Select(d => d.RoleId).Contains(Convert.ToInt32(temp1.RoleId))*/
            select new ApplicationLogDto
            {
                BAppId = temp1.Id,
                BAppType = temp1.BAppType,
                FunModule = temp1.FunModule,
                Menu = temp1.Menu,
                UserName = temp3.Surname + temp3.Name,
                UserID = temp3.Id,
                WfName = temp2.WfName,
                BusinessNumber= temp1.BusinessNumber,
                BusinessDesc= temp1.BusinessDesc,
                ApplicationDate = temp1.ApplicationDate
            };
            if (inputDto.userNameList != null)
            {
                query = query.Where(d => inputDto.userNameList.Contains(d.UserName));
            }
            if (inputDto.bappTypeList != null)
            {
                query = query.Where(d => inputDto.bappTypeList.Contains(d.BAppType.Value));
            }
            int count = query.ToList().Count();
            query = query.PageBy(inputDto);
            return new PagedResultDto<ApplicationLogDto>(count, query.ToList());
        }
        /// <summary>
        /// 根据业务Id获取业务信息
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public BusinessApplication GetBusinessApplicationById(Guid guid)
        {
            return _businessApplicationRepository.Get(guid);
        }

        private static string GetEnumDesc(System.Enum parm)
        {
            FieldInfo enumInfo = parm.GetType().GetField(parm.ToString());
            if (enumInfo == null)
            {
                return "";
            }
            DescriptionAttribute[] enumAttributes
                = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (enumAttributes.Length > 0)
            {
                return enumAttributes[0].Description;
            }
            return parm.ToString();
        }
        /// <summary>
        /// 发送信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="TargetUserId"></param>
        /// <param name="RoleId"></param>
        /// <param name="Title"></param>
        /// <param name="Message"></param>
        /// <param name="SharedMessageId"></param>
        /// <param name="sendMode"></param>
        /// <param name="intAffairRemindId"></param>
        /// <param name="IsWorkFlow"></param>
        public void SendWorkFlowMessage(long? UserId, long? TargetUserId, string RoleId, string Title, string Message, Guid? SharedMessageId, MessageSendingMode sendMode,int? AffairRemindId=0,   bool IsWorkFlow = true)
        {
            AffairMessage affairMessage = new AffairMessage();
            affairMessage.AffairRemindId = AffairRemindId.Value;
            affairMessage.UserId = UserId.Value;
            affairMessage.TargetUserId = TargetUserId;
            affairMessage.RoleId = RoleId;
            affairMessage.Title = Title;
            affairMessage.Message = Message;
            affairMessage.SharedMessageId = SharedMessageId;
            affairMessage.SendMode =(int) sendMode;
            affairMessage.IsWorkFlow = IsWorkFlow;
            affairMessage.ChangeReadState(ChatMessageReadState.Unread);
            _affairMessageRepository.Insert(affairMessage);
        }

        /// <summary>
        /// 根据角色Id获取角色列表
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public List<UserListDto> GetUserByRole(int roleId)
        {
            var temp = (from cc in _userRoleRepository.GetAll().Where(d=>d.RoleId==roleId)
                        join mm in _userRepository.GetAll() on cc.UserId equals mm.Id
                        orderby mm.CreationTime
                        select new UserListDto
                        {
                            Id=mm.Id,
                            Name = mm.Name,
                            Surname = mm.Surname,
                            UserName = mm.UserName,
                            EmailAddress = mm.EmailAddress,
                            PhoneNumber = mm.PhoneNumber,
                            ProfilePictureId = mm.ProfilePictureId,
                            IsEmailConfirmed = mm.IsEmailConfirmed,
                            IsActive = mm.IsActive,
                            CreationTime = mm.CreationTime,
                        }).ToList();
            return temp;
        }

      
    }
}
